(function () {
    angular.module('app')
        .component('xxLogin', {
            templateUrl: '/app/login/login.html',
            controller: ctrl
        });

    function ctrl($scope,LoginFactory,urlCnst,userService,$state) {

        $scope.login = function (body) {
            function cb(err, res) {
                //TODO set userService
                //console.log(err,res);
                if (!err){
                    userService.setUser(res['res']);
                    //console.log(res['res']);
                    $state.go('show.home')
                }
            }
            if (!body['username'] || !body['password']) {
                urlCnst.notice('请输入用户名和密码');
                return;
            }
            LoginFactory.login(body, cb);
        };
        $scope.register = function () {
            $state.go('register')
        }
        $scope.home = function () {
            $state.go('show.home')
        }
    }
})();
